package com.atguigu.springcloud.controller;

import com.atguigu.springcloud.common.CommonResult;
import com.atguigu.springcloud.entities.Payment;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;

/**
 * @author : leimingchao
 * @date Date : 2022年02月14日 19:44
 */

@RestController
public class PaymentController {

    @Value(value = "${server.port}")
    private String serverPort;

    public static HashMap<Long,Payment> hashMap = new HashMap<>();

    static {
        hashMap.put(1L, new Payment(1L, "b033705040e54addb8ba1d2055501ef2"));
        hashMap.put(2L, new Payment(2L, "b086ff223e274133950a7d2e8e804163"));
        hashMap.put(3L, new Payment(3L, "691c408c2fb04378ada28901b2cf9bcf"));
    }

    @GetMapping(value = "/paymentSQL/{id}")
    public CommonResult<Payment> paymentSQL(@PathVariable(value = "id") Long id) {
        Payment payment = hashMap.get(id);
        CommonResult<Payment> result = new CommonResult<>(200, "from mysql, serverPort:" + serverPort, payment);
        return result;
    }
}
